<template>
  <div>
    <el-dialog
      title="巡查任务记录"
      :visible="dialogVisible"
      custom-class="custom-dialog"
      :before-close="handleClose"
      @open="initData"
      width="78%"
      class="dialogClass"
    >
      <div class="page-container">
        <SearchPanel @change="handleSearchPanelChange">
          <el-form
            ref="queryForm"
            class="query-more-form"
            size="mini"
            label-width="100px"
            :model="query"
          >
            <el-row :gutter="21">
              <el-col :span="16">
                <el-form-item label="综合条件">
                  <el-input
                    v-model="query.query"
                    class="search-ipt"
                    placeholder="请输入查询条件"
                    maxlength="255"
                  />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="10">
            <el-form-item label="时间区间">
              <el-date-picker
                v-model="query.startTime"
                type="datetimerange"
                size="mini"
                range-separator="-"
                start-placeholder="开始"
                end-placeholder="结束"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="任务部门">
              <el-select
                class="w-100"
                v-model="query.deptName"
                placeholder="请选择任务部门"
                clearable
              >
                <el-option
                  v-for="item in department"
                  :key="item.code"
                  :value="item.sysDeptVo.deptName"
                  :label="item.sysDeptVo.deptName"
                />
              </el-select>
            </el-form-item>
          </el-col> -->
              <el-col :span="4" class="btn-col">
                <el-button size="mini" class="search-btn" @click="select"
                  >查询</el-button
                >
              </el-col>
            </el-row>
          </el-form>
        </SearchPanel>
        <div class="table-container">
          <div class="table-tools-panel table-flex-row">
            <el-button class="flush-btn" size="mini" icon="el-icon-refresh"
              >刷新</el-button
            >
            <div>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-set-up"
              ></el-button>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-share"
              ></el-button>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-printer"
              ></el-button>
            </div>
          </div>
          <div class="table-list-panel">
            <el-table
              v-loading="tableLoading"
              border
              size="small"
              :data="tableData"
              :height="isShow ? 'calc(100vh - 410px)' : 'calc(100vh - 335px)'"
              style="width: 100%"
            >
              <el-table-column type="selection" width="45" />
              <el-table-column
                prop="nodeNowDeptName"
                label="办理部门"
                show-overflow-tooltip
              />
              <el-table-column prop="startTime" label="巡检时间" width="260">
                <template slot-scope="scope">
                  <div>
                    {{ parseTime(scope.row.creatTime) }}
                  </div></template
                >
              </el-table-column>
              <el-table-column
                prop="categoryCompleteName"
                label="检查事项"
                show-overflow-tooltip
              />
              <el-table-column
                prop="creatUserName"
                label="创建人"
                show-overflow-tooltip
              />
              <el-table-column
                prop="nodeNowName"
                label="当前环节"
                width="100"
                show-overflow-tooltip
              />

              <el-table-column label="操作" width="90">
                <template slot-scope="scope">
                  <!-- <el-button
                    class="table-inner-btn"
                    type="text"
                    size="mini"
                    @click.native="handleDetail(scope.row)"
                    >详情</el-button
                  > -->
                  <el-button
                    class="table-inner-btn"
                    type="text"
                    size="mini"
                    @click.native="handleUpdate(scope.row)"
                    >记录</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination-panel">
            <Pagination
              :total="query.total"
              :page.sync="query.pageNum"
              :limit.sync="query.pageSize"
              @pagination="initData"
            />
          </div>
        </div>

        <!-- <InspectionItemDetailsDialog
          :dialogVisible="DetailsDialog"
          :caseId="caseId"
          @closeDialog="DetailsDialog = false"
        /> -->
      </div>
    </el-dialog>
  </div>
</template>
<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getReportList } from "@/api/system/inspectionItemRecord";
import { parseTime } from "@/utils/index";
import InspectionItemDetailsDialog from "./inspectionItemDetailsDialog";
import { detailsUrl } from "@/utils/changeUrl";

export default {
  name: "CaseDealDispatch",
  components: {
    SearchPanel,
    Pagination,
    InspectionItemDetailsDialog
  },
  data() {
    return {
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        query: ""
      },
      tableLoading: false,
      DetailsDialog: false,
      tableData: [],
      department: [],
      isShow: true
    };
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    taskId: {
      type: Number,
      default: null
    }
  },
  created() {
    this.initData();
  },
  watch: {
    taskId(val) {
      this.query.taskId = val;
      this.select();
    }
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    handleClose() {
      this.$emit("closeDialog");
    },
    parseTime,
    initData() {
      this.select();
    },
    select() {
      this.tableLoading = true;
      getReportList(this.query)
        .then(result => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    handleUpdate(val) {
      let href_url = location.href;
      let url = href_url.match(/access_token=(\S*)&expireTime/)[1];
      let addressUrl = `${detailsUrl}/km/review/km_review_main/kmReviewMain.do?access_token=${url}&method=view&fdId=${
        val.id
      }`;
      window.open(addressUrl);
    }
  }
};
</script>
